package com.xubeizhi.controller;

import com.xubeizhi.common.Result;
import com.xubeizhi.entity.Article;
import com.xubeizhi.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/article")
@CrossOrigin
public class ArticleController {


    @Autowired
    private ArticleService articleService;

    @PostMapping("/create")
    public Result createArticle(@RequestBody Article article){
        return articleService.createArticle(article);
    }

    @GetMapping("/page")
    public Result listArticle(Integer pageNum,Integer pageSize){
        return articleService.listArticleInfo(pageNum,pageSize);
    }

    @GetMapping("/info")
    public Result getArticleById(Integer id){
        return articleService.getArticleById(id);
    }

    @PutMapping("/update")
    public Result updateArticle(@RequestBody Article article){
        return articleService.updateArticle(article);
    }

    @DeleteMapping("/remove")
    public Result deleteArticle(Integer id){
        return articleService.deleteArticle(id);
    }

    @GetMapping("/search")
    public Result SearchArticle(String content,String status){
        return articleService.SearchArticle(content,status);
    }

    @GetMapping("/listarticle")
    public Result ListArticle(Integer pageNum, Integer pageSize, @RequestParam(required = false) Integer categoryId, @RequestParam(required = false) String status){
        return articleService.listArticles(pageNum,pageSize,categoryId,status);
    }

    @PostMapping("/falsedelete")
    public Result FalseDeleteArticle(@RequestBody Article article){
        return articleService.deleteByArticle(article);
    }
}
